#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QTextCodec>

#include "include/undefinedItem.h"
#include "include/mainItem.h"
#include "include/define.h"
#include "include/myuart.h"
#include "include/serialframe.h"
#include "include/msgproc.h"

class QLabel;
class QTimer;
class QAction;
class QToolBar;
class QGroupBox;
class QPushButton;


class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = 0);
    ~MainWindow();

signals:
    // 串口中的数据构成了应用层数据帧，通知应用层消息处理类MsgProc
    void sig_aplDataComing();


private slots:
    void importConfSlot();
    void exportConfSlot();
    void ctrlSettingSlot();
    void keyWordSearchSlot();
    void regionSearchSlot();
    void typeSearchSlot();
    void pageSeqIncSlot();
    void pageSeqDesSlot();
    void switchDisPlaySlot();
    void searchItemSlot(QString itemId);
    void displayTime();
    void initItem();
    void clearSlot();

    void handleSerialData(QByteArray &msg);

    // 串口有原始数据到来
    void uartDataCame();
    void slot_send_frame(QByteArray msg);

private:
    void init();
    void initSerial();
    void createAction();
    void createToolBars();
    void createStatusBars();
    void updateStatusBars();
    void displayItem();
    void testUDisk();

    void feedbackBlink();
    void malfunctionBlink();
    void highLightItem(int itemId);
    void switchItemStatus();

    int feedbackFlag;
    int feedbackTemp;
    int malfunctionTemp;
    int malfunctionFlag;
    int getNumOfTotalItem();
    int getMaxPages(int numOfTotalItemTemp);

    void timerEvent(QTimerEvent *event);
    void showEvent(QShowEvent *);

    int myTimerId;// 定时器间隔
    bool displayMode;//显示简单图标还是复杂图标，true时显示复杂图标，false时显示简单图标
    unsigned int pageSeq;//页序号
    unsigned int maxPageSeq;//最大的页序号
    int numOfTotalItem;
    int itemStatusId;

    QToolBar *toolBar;

    QAction *importConf;
    QAction *exportConf;
    QAction *ctrlSetting;
    QAction *keyWordSearch;
    QAction *regionSearch;
    QAction *typeSearch;
    QAction *simpleItemDisPlay;
    QAction *clear;
    QAction *pageUp;
    QAction *pageDown;
    QAction *quit;

    QLabel *timeLabel;
    QLabel *conn;
    QLabel *connState;
    QLabel *item;
    QLabel *itemState;
    QLabel *uIcon;

//    QByteArray gSt2qba;
//    QString char2utf8;
//    QString iState;
//    QString gb2utf8;

//    std::string str;
//    char *qba2char;

//    QTextCodec *utf8;

    MyUart *dev_serial;  //  串口设备类
    SerialFrame *app_data_frame; // 串口数据帧封装和解封
    MsgProc *msg_processor;  //  应用层消息处理器
    QSocketNotifier *uart_notifier;  // 串口数据监听器

    QGroupBox *groupBox;

    MainItem *mItem[NUM_OF_TOTAL_ITEM];
    UndefinedItem *uItem[NUM_OF_TOTAL_ITEM];





};

#endif // MAINWINDOW_H
